<template>
  <div >
    <el-form label-width="160px"  v-loading="loading">

      <el-form-item label="银行转账">
        <el-upload
          class="avatar-uploader"
          :action="$uploadUrl"
          :show-file-list="false"
          :on-success="handleAbroadSuccess"
           :headers="{
             Authorization: getToken()
           }"
        >
          <img
            v-if="formData.transfer_abroad_pay"
            :src="$imageBaseUrl+ formData.transfer_abroad_pay"
            class="avatar"
          />
     
          <i v-else class="icon iconfont icon-increase avatar-uploader-icon"></i>
        </el-upload>
        </el-form-item>
          <el-form-item label="收款银行">
            <el-input v-model="formData.transfer_abroad_bank"></el-input>
        </el-form-item>
         <el-form-item label="收款账号">
            <el-input v-model="formData.transfer_abroad_account"></el-input>
        </el-form-item>
      
        <el-form-item label="收款名称">
            <el-input v-model="formData.transfer_abroad_account_name"></el-input>
        </el-form-item>
    </el-form>
    <div class="flex flex-start " style="margin-left:160px;">
      <el-button type="primary" @click="save()" :loading="saveLoading"
      >保存</el-button
    >
    </div>
    
  </div>
</template>

<script setup>
import { defineComponent, onMounted, getCurrentInstance, ref } from "vue";
import { getToken } from '@/utils/sys';
const {
  appContext: {
    config: { globalProperties },
  },
} = getCurrentInstance();

const { $storage, $http, $ekMessage, $ekMessageBox,$imageBaseUrl,$uploadUrl  } = globalProperties;

const saveLoading = ref(false);
const formData = ref({
  transfer_wechat_pay: "",
  transfer_alipay_pay: "",
  transfer_alipay_account: "",
  transfer_alipay_account_name: "",
  transfer_abroad_pay: "",
  transfer_abroad_account: "",
  transfer_abroad_account_name: "",
  transfer_abroad_bank: "",
});
const loading = ref(false)
const init = () => {
  loading.value = true;
  $http
    .get(`business/config/getConfigByGroup?authCode=FUNCTION_CONFIG`,{ params:{code:'CONFIG_GROUP_TRANSFER_PAY'}})
    .then((res) => {
      if (res.status === "success") {
       
        if(res.data.list?.length){
            for(let item of res.data.list){
                formData.value[item.config_key] =  item.config_value;
            }
        }
        loading.value = false;
      }
    });
};
const save = () => {
  $http
    .post(`business/config/save?authCode=FUNCTION_CONFIG&code=CONFIG_GROUP_TRANSFER_PAY`, {
      ...formData.value
    })
    .then((res) => {
        if(res.status =='success'){
             $ekMessage.success('操作成功');

        }
    });
};
const handleSuccess = (res)=> {
     if (res.status === "success") {
        formData.value.transfer_wechat_pay = res.data.path
      }
}
const handleAlipaySuccess = (res)=> {
     if (res.status === "success") {
        formData.value.transfer_alipay_pay = res.data.path
      }
}
const handleAbroadSuccess = (res)=> {
     if (res.status === "success") {
        formData.value.transfer_abroad_pay = res.data.path
      }
}

onMounted(async () => {
  init();
});
</script>
<style scoped lang="scss">
:deep(.avatar-uploader) {
  .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    &:hover {
      border-color: #409eff;
    }
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
}
</style>
